import 'package:flutter/material.dart';

import '../common/const/app_color_const.dart';
import '../common/const/app_style_const.dart';
import '../common/enum/btn_enum.dart';
import 'ripple_container.dart';

class GradientBtn extends StatelessWidget {
  final String label;
  final TextStyle labelStyle;
  final EdgeInsets padding;
  final Gradient gradient;
  final WidgetBuilder? labelRightBuilder;
  final WidgetBuilder? labelLeftBuilder;
  final GestureTapCallback? onTap;
  final GradientBtnType gradientBtnType;

  const GradientBtn(
      {required this.label,
      this.labelRightBuilder,
      this.labelLeftBuilder,
      this.gradientBtnType = GradientBtnType.primary,
      this.labelStyle = gradientBtnPrimaryLabelTextStyle,
      this.gradient = const LinearGradient(
          colors: [primaryTransparentColor3, primaryTransparentColor4]),
      this.padding =
          const EdgeInsets.only(left: 8.0, right: 8.0, top: 2.0, bottom: 3.0),
      this.onTap,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Gradient btnGradient = gradient;
    TextStyle btnLabelStyle = labelStyle;

    if (gradientBtnType == GradientBtnType.primary) {
      btnGradient = const LinearGradient(
          colors: [primaryTransparentColor3, primaryTransparentColor4]);
      btnLabelStyle = gradientBtnPrimaryLabelTextStyle;
    }

    if (gradientBtnType == GradientBtnType.red) {
      btnGradient = const LinearGradient(
          colors: [redTransparentColor3, redTransparentColor4]);
      btnLabelStyle = gradientBtnRedLabelTextStyle;
    }

    if (gradientBtnType == GradientBtnType.gray) {
      btnGradient = const LinearGradient(
          colors: [grayTransparentColor3, grayTransparentColor4]);
      btnLabelStyle = gradientBtnGrayLabelTextStyle;
    }

    if (gradientBtnType == GradientBtnType.green) {
      btnGradient = const LinearGradient(
          colors: [greenTransparentColor3, greenTransparentColor4]);
      btnLabelStyle = gradientBtnGreenLabelTextStyle;
    }


    return RippleContainer(
        borderRadius: BorderRadius.circular(20),
        onTap: onTap,
        child: Container(
          alignment: Alignment.center,
          padding: padding,
          decoration: BoxDecoration(
              gradient: btnGradient, borderRadius: BorderRadius.circular(20)),
          child: Row(
            children: [
              if (null != labelLeftBuilder) labelLeftBuilder!(context),
              Text(
                label,
                style: btnLabelStyle,
              ),
              if (null != labelRightBuilder) labelRightBuilder!(context)
            ],
          ),
        ));
  }
}
